package _04_HashMap和HashTable的区别;

import org.junit.Test;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;

/**
 * @author 董代恒
 * @version 1.0
 */
public class HashMapAndHashTable {

    @Test
    public void test01(){
        /*
        HashMap默认初始容量：16
        HashTable默认初始容量：11
        Hashtable扩容时，将容量变为原来的2倍加1，而HashMap扩容时，将容量变为原来的2倍

         */
        HashMap hashMap = new HashMap();
        hashMap.put(1,"哈哈");
        hashMap.put(2,"哈哈");
        hashMap.put(3,null);
        hashMap.put(4,null);
        for (Object o : hashMap.keySet()) {
            System.out.println(hashMap.get(o));
        }
        Hashtable hashtable = new Hashtable();

        hashtable.put(1,"哈哈");
        hashtable.put(2,"哈哈");
        Enumeration elements = hashtable.elements();
        for (Object o : hashtable.keySet()) {
            System.out.println(o);
        }
    }
}
